<?php

namespace App\Model\PssModel;

use App\Model\BaseModel\BasePssModel;
use Hyperf\DbConnection\Db;

class ShopHomeGroupConfig extends BasePssModel
{
    protected $table='shop_home_group_config';

    public function getGroupConfigs()
    {
        return $this->where('group_status',1)
            ->select([
                'id',
                'group_name',
            ])
            ->get()
            ->toArray();
    }

    public function getGroupConfigsDetail($params)
    {
        $body  = $params['body'];
        $binfo = $params['binfo'];

        if (empty($body['group_id'])){
            return [];
        }
        $data = $this->where('group_status',1)->where('id',$body['group_id'])->select([
            'id',
            'group_name',
            'group_images',
            Db::raw('CONCAT(group_goods_id,"") as group_goods_id')
        ])->first();
        $group_detail = $data ? $data->toArray() : [];
        if (empty($group_detail)){
            return [];
        }
        $group_detail['group_images'] = json_decode($group_detail['group_images'],true);
        $group_goods  = ShopGoodsGroupList::instance()->getGoodsGroupPageList([
           'body'=>[
               'group_id' => $group_detail['group_goods_id'],
               'page'     => $body['page'] ?? 1,
               'limit'    => $body['limit'] ?? 10
           ], 'binfo'=>$binfo
        ]);
        return [
            'group_detail'=> $group_detail,
            'group_goods' => $group_goods['data'] ?? []
        ];
    }

}